package com.ztools.wx.handler;

import cn.hutool.core.util.StrUtil;
import com.ztools.wx.async.WxMpAsyncTasks;
import lombok.AllArgsConstructor;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @Author:seeTools
 * @Date: 2023/4/9  12:55
 * @Version 1.0
 */
@AllArgsConstructor
@Component
public class ScanHandler extends AbstractHandler {

    private final WxMpAsyncTasks wxMpAsyncTasks;

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMpXmlMessage, Map<String, Object> map, WxMpService wxMpService, WxSessionManager wxSessionManager) throws WxErrorException {
        logger.info("扫码事件用户 OPENID: " + wxMpXmlMessage.getFromUser());
        String event = wxMpXmlMessage.getEvent();
        String eventKey = wxMpXmlMessage.getEventKey();
        logger.info("扫码请求:{},{}", event, eventKey);
        // 从eventKey中获取扫码的场景值，然后进行后续的业务处
        if (StrUtil.isNotEmpty(eventKey)) {
//            wxMpAsyncTasks.scanQrcode(wxMpXmlMessage.getFromUser(), eventKey);
        }
        return null;
    }

}
